import React from 'react';
import {GForm} from 'geminis-react';
import {message} from 'antd';

export default () => {
  const schema = {
    data: {
      url: '/login',
      method: 'POST',
      format: 'form',
    },
    layout: {
      layout: 'vertical',
      labelCol: null,
      wrapperCol: null,
      size: 'large',
      submit: {
        text: '登录',
        'x-component-props': {
          block: 'block',
          size: 'large',
        },
      },
    },
    fields: {
      type: 'object',
      properties: {
        username: {
          type: 'string',
          title: '',
          required: true,
          'x-decorator': 'FormItem',
          'x-component': 'Input',
          'x-component-props': {
            placeholder: '请输入用户名',
            prefix: "{{icon('icon-user')}}",
          },
        },
        password: {
          type: 'string',
          title: '',
          required: true,
          'x-decorator': 'FormItem',
          'x-component': 'Password',
          'x-component-props': {
            placeholder: '请输入密码',
            prefix: "{{icon('icon-password')}}",
          },
        },
      },
    },
  };

  const onSubmitted = (value, resp) => {
    if (resp.status === 200) {
      message.success('跳转到首页');
    } else {
      message.error(resp.msg);
    }
  };

  return <GForm schema={schema} onSubmitted={onSubmitted}/>;
};
